package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.activity.client.SeckillFeignClient;
import com.atguigu.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author: Mamba
 * @version: 1.0
 * @Time: 2021/1/18 20:31
 * @Description:    秒杀管理
 */
@Controller
public class SeckillController {

    @Autowired
    private SeckillFeignClient seckillFeignClient;
    //秒杀频道首页
    @GetMapping("/index")
    public String index(Model model){
      List<SeckillGoods> seckillGoodsList = seckillFeignClient.list();
      model.addAttribute("list",seckillGoodsList);

      return "seckill/index";
    }

    //去商品详情页面
    @GetMapping("/seckill/{skuId}.html")
    public String seckillItem(@PathVariable Long skuId,Model model){
        SeckillGoods seckillGoods = seckillFeignClient.getSeckillGoods(skuId);
        model.addAttribute("item",seckillGoods);

        return "seckill/item";
    }

    //去立即抢购页面
    @GetMapping("/seckill/queue.html")
    public String queue(Long skuId,String skuIdStr,Model model){
        model.addAttribute("skuId",skuId);
        model.addAttribute("skuIdStr",skuIdStr);
        return "seckill/queue";
    }
}
